package micro.beauty.common.mybatis;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * @Description: mybatis-plus 查询条件
 * @Author: Liuliya
 * @CreateDate: 2020/9/16 23:00
 * @Version: 0.0.1
 */
public class Condition {

    private Condition() {
        //nothing to do
    }

    public static <T> Page<T> getPage(PageQuery pageQuery) {
        return getPage(pageQuery, false);
    }

    private static <T> Page<T> getPage(PageQuery query, boolean sort) {
        Page<T> page = new Page<>(query.getCurrent(), query.getSize());
        if (sort) {
            if (query.getAscs().length > 0) {
                page.addOrder(OrderItem.ascs(query.getAscs()));
            }
            if (query.getDescs().length > 0) {
                page.addOrder(OrderItem.descs(query.getDescs()));
            }
        }
        return page;
    }
}
